package com.example.sangong.myenum;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public enum GenderEnum {
    WOMAN(1, "男"),
  MAN(0, "女"),
    ;

    private Integer code;
    private String desc;

    private static Map<Integer, String> map = new HashMap<>();
    private static Map< String,Integer> descMap = new HashMap<>();
    static {
        for (GenderEnum value : GenderEnum.values()) {
            map.put(value.getCode(), value.getDesc());
            descMap.put(value.getDesc(), value.getCode());
        }
    }

    public static String convert(Integer code){
        return map.get(code);
    }
    public static Integer getVal(String desc){
        return descMap.get(desc);
    }

    GenderEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }
}
